<template>
	<!-- 弹框遮罩 -->
	<div v-if="visible" class="seckill-countdown">
		<!-- 弹框主体 -->
		<div class="seckill-countdown__modal" :class="{ 'seckill-countdown__modal--show': visible }">
			<!-- 倒计时显示区域 -->
			<div class="seckill-countdown__display">
				<!-- 酷炫背景效果 -->
				<div class="seckill-countdown__bg-effects">
					<!-- 动态粒子 -->
					<div class="seckill-countdown__particles">
						<div class="particle" v-for="n in 15" :key="n"></div>
					</div>

					<!-- 旋转几何图形 -->
					<div class="seckill-countdown__geometry">
						<div class="geo-ring geo-ring--1"></div>
						<div class="geo-ring geo-ring--2"></div>
						<div class="geo-hexagon"></div>
						<div class="geo-triangle"></div>
					</div>

					<!-- 光晕波浪 -->
					<div class="seckill-countdown__wave-glow">
						<div class="wave-circle wave-circle--1"></div>
						<div class="wave-circle wave-circle--2"></div>
						<div class="wave-circle wave-circle--3"></div>
					</div>

					<!-- 彩色光束 -->
					<div class="seckill-countdown__light-beams">
						<div class="light-beam light-beam--1"></div>
						<div class="light-beam light-beam--2"></div>
						<div class="light-beam light-beam--3"></div>
						<div class="light-beam light-beam--4"></div>
					</div>
				</div>

				<div class="seckill-countdown__seconds">
					<div class="seckill-countdown__title">倒计时开始</div>
					<span class="seckill-countdown__seconds-digit">{{ endTime.s }}</span>
					<div class="seckill-countdown__seconds-unit">秒</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script setup>
	import {
		ref,
		computed,
		watch,
		onMounted,
		onUnmounted
	} from 'vue';

	// Props
	const props = defineProps({
		visible: {
			type: Boolean,
			default: false,
		},
		endTime: {
			type: Object,
			required: false,
		},
	});
</script>

<style lang="scss" scoped>
	.seckill-countdown__title {
		font-size: 1.5rem;
	}

	.seckill-countdown {
		position: fixed;
		top: 0;
		left: 0;
		width: 100vw;
		height: 100vh;
		background: rgba(236, 240, 241, 0.4);
		display: flex;
		align-items: center;
		justify-content: center;
		z-index: 1000;
		backdrop-filter: blur(3px);
		animation: fadeIn 0.3s ease-out;

		&__modal {
			position: relative;
			width: 340px;
			height: 340px;
			background: #9b59b6;
			backdrop-filter: blur(20px);
			border: 1px solid rgba(255, 255, 255, 0.2);
			border-radius: 50%;
			box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.3);
			display: flex;
			align-items: center;
			justify-content: center;
			overflow: hidden;
			transform: scale(0.8) translateY(50px);
			opacity: 0;
			transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);

			&::before {
				content: '';
				position: absolute;
				top: 0;
				left: 0;
				right: 0;
				bottom: 0;
				background: linear-gradient(45deg,
						rgba(255, 255, 255, 0.1) 0%,
						rgba(255, 255, 255, 0.05) 50%,
						rgba(255, 255, 255, 0.1) 100%);
				border-radius: inherit;
			}

			&--show {
				transform: scale(1) translateY(0);
				opacity: 1;
			}
		}

		&__title {
			font-size: 1.5rem;
			font-weight: bold;
			background: linear-gradient(45deg,
					#ff6b6b 0%,
					#feca57 25%,
					#48dbfb 50%,
					#ff9ff3 75%,
					#54a0ff 100%);
			-webkit-background-clip: text;
			-webkit-text-fill-color: transparent;
			background-clip: text;
			filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2)) drop-shadow(0 0 8px rgba(255, 107, 107, 0.2));
			margin-bottom: 10px;
			letter-spacing: 2px;
			position: relative;
			z-index: 15;
		}

		&__seconds-unit {
			font-size: 1.2rem;
			font-weight: 600;
			background: linear-gradient(45deg,
					#fd79a8 0%,
					#fdcb6e 30%,
					#6c5ce7 60%,
					#a29bfe 100%);
			-webkit-background-clip: text;
			-webkit-text-fill-color: transparent;
			background-clip: text;
			filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.15)) drop-shadow(0 0 6px rgba(253, 121, 168, 0.2));
			margin-top: 5px;
			letter-spacing: 1px;
			position: relative;
			z-index: 15;
		}

		&__display {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			height: 100%;
			padding: 0;
			z-index: 5;
			position: relative;
			overflow: hidden;
		}

		&__seconds {
			display: flex;
			align-items: center;
			justify-content: center;
			position: relative;
			width: 100%;
			height: 100%;
			z-index: 10;
			flex-direction: column;
		}

		&__seconds-digit {
			font-size: 7.5rem;
			font-weight: 900;
			color: #fc5c65;
			-webkit-text-stroke: 1px rgba(204, 46, 67, 0.3);
			z-index: 3;
			position: relative;
			font-family: 'Arial Black', sans-serif;
			letter-spacing: -8px;
			animation: pulse3D 1s ease-in-out infinite;
			transition: all 0.3s ease;
			transform-style: preserve-3d;
		}

		&__seconds-bg {
			position: absolute;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);
			width: 320px;
			height: 320px;
			background: rgba(255, 255, 255, 0.1);
			border-radius: 50%;
			border: 2px solid rgba(255, 71, 87, 0.3);
			backdrop-filter: blur(10px);
			z-index: 1;
			animation: rotate 10s linear infinite;
			box-shadow: inset 0 4px 8px rgba(255, 255, 255, 0.3), 0 8px 32px rgba(255, 71, 87, 0.2);
		}

		&__seconds-glow {
			position: absolute;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);
			width: 380px;
			height: 380px;
			background: radial-gradient(circle, rgba(255, 71, 87, 0.1) 0%, transparent 70%);
			border-radius: 50%;
			z-index: 0;
			animation: breathe 2s ease-in-out infinite alternate;
		}

		// 旋转色彩环
		&__color-ring {
			position: absolute;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);
			width: 360px;
			height: 360px;
			border-radius: 50%;
			opacity: 0.4;
			z-index: 0;
			animation: colorRingRotate 8s linear infinite;

			// 使用伪元素创建彩色圆环，更好的兼容性
			&::before {
				content: '';
				position: absolute;
				top: 0;
				left: 0;
				right: 0;
				bottom: 0;
				border-radius: 50%;
				padding: 3px;
				background: linear-gradient(45deg,
						#ff6b35 0%,
						#f7931e 12.5%,
						#ffd93d 25%,
						#6bcf7f 37.5%,
						#4ecdc4 50%,
						#45b7d1 62.5%,
						#a55eea 75%,
						#fd79a8 87.5%,
						#ff6b35 100%);
				mask: radial-gradient(circle, transparent 176px, black 180px);
				-webkit-mask: radial-gradient(circle, transparent 176px, black 180px);
			}
		}

		&__seconds-label {
			font-size: 2rem;
			color: rgba(100, 100, 100, 0.8);
			font-weight: bold;
			text-shadow: 0 2px 8px rgba(255, 255, 255, 0.6);
			position: relative;
			z-index: 4;
		}

		&__progress-container {
			width: 100%;
			margin-bottom: 30px;
		}

		&__progress-header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 8px;
		}

		&__progress-label {
			font-size: 0.9rem;
			color: rgba(100, 100, 100, 0.7);
			font-weight: 500;
		}

		&__progress-percentage {
			font-size: 1rem;
			font-weight: bold;
			color: #ff4757;
			text-shadow: 0 1px 3px rgba(255, 71, 87, 0.3);
			padding: 4px 8px;
			background: rgba(255, 71, 87, 0.1);
			border-radius: 12px;
			border: 1px solid rgba(255, 71, 87, 0.2);
			backdrop-filter: blur(5px);
			animation: percentageGlow 2s ease-in-out infinite alternate;
		}

		&__progress {
			width: 100%;
			height: 8px;
			background: rgba(200, 200, 200, 0.2);
			border-radius: 4px;
			overflow: hidden;
			box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
		}

		&__progress-bar {
			height: 100%;
			background: #ff4757;
			border-radius: 4px;
			transition: width 0.1s ease;
			position: relative;
			box-shadow: 0 2px 8px rgba(255, 71, 87, 0.3);

			&::after {
				content: '';
				position: absolute;
				top: 0;
				left: 0;
				right: 0;
				bottom: 0;
				background: linear-gradient(90deg,
						transparent,
						rgba(255, 255, 255, 0.8),
						transparent);
				animation: shimmer 2s linear infinite;
			}
		}

		&__tip {
			text-align: center;

			p {
				font-size: 1.1rem;
				color: rgba(100, 100, 100, 0.8);
				margin: 0;
			}

			&--ended {
				p {
					font-size: 1.5rem;
					font-weight: bold;
					color: #ff4757;
					animation: bounce 0.6s ease-in-out infinite;
				}
			}
		}

		&__effects {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			bottom: 0;
			pointer-events: none;
			z-index: 1;
		}

		&__spark {
			position: absolute;
			width: 4px;
			height: 4px;
			background: rgba(150, 150, 150, 0.6);
			border-radius: 50%;
			opacity: 0;
			animation: sparkle 3s linear infinite;

			@for $i from 1 through 20 {
				&:nth-child(#{$i}) {
					left: random(100) * 1%;
					top: random(100) * 1%;
					animation-delay: random(300) * 0.01s;
					animation-duration: (1 + random(200) * 0.01) * 1s;
				}
			}
		}

		// 酷炫背景效果容器
		&__bg-effects {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			bottom: 0;
			pointer-events: none;
			z-index: 1;
		}

		// 动态粒子效果
		&__particles {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			bottom: 0;

			.particle {
				position: absolute;
				width: 4px;
				height: 4px;
				background: linear-gradient(45deg,
						rgba(255, 107, 53, 0.8),
						rgba(255, 140, 66, 0.8),
						rgba(255, 182, 108, 0.8));
				border-radius: 50%;
				box-shadow: 0 0 6px rgba(255, 107, 53, 0.6), 0 0 12px rgba(255, 107, 53, 0.4),
					0 0 18px rgba(255, 107, 53, 0.2);
				animation: particleFloat 4s linear infinite;

				// 为每个粒子设置不同的位置和延迟
				@for $i from 1 through 15 {
					&:nth-child(#{$i}) {
						left: random(100) * 1%;
						top: random(100) * 1%;
						animation-delay: random(400) * 0.01s;
						animation-duration: (3 + random(300) * 0.01) * 1s;
						transform: scale(random(100) * 0.01 + 0.5);
					}
				}
			}
		}

		// 旋转几何图形
		&__geometry {
			position: absolute;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);
			width: 300px;
			height: 300px;

			.geo-ring {
				position: absolute;
				border: 2px solid;
				border-radius: 50%;

				&--1 {
					top: 10%;
					left: 10%;
					width: 80%;
					height: 80%;
					border-color: rgba(255, 107, 53, 0.3);
					animation: geoRotate 8s linear infinite;
				}

				&--2 {
					top: 20%;
					left: 20%;
					width: 60%;
					height: 60%;
					border-color: rgba(255, 140, 66, 0.4);
					animation: geoRotate 6s linear infinite reverse;
				}
			}

			.geo-hexagon {
				position: absolute;
				top: 30%;
				left: 30%;
				width: 40%;
				height: 40%;
				background: linear-gradient(45deg,
						rgba(255, 182, 108, 0.2),
						rgba(255, 140, 66, 0.3));
				clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
				animation: geoFloat 4s ease-in-out infinite;
			}

			.geo-triangle {
				position: absolute;
				top: 35%;
				left: 35%;
				width: 30%;
				height: 30%;
				background: linear-gradient(135deg,
						rgba(255, 107, 53, 0.3),
						rgba(255, 182, 108, 0.2));
				clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
				animation: geoSpin 5s ease-in-out infinite;
			}
		}

		// 光晕波浪效果
		&__wave-glow {
			position: absolute;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);

			.wave-circle {
				position: absolute;
				border: 1px solid;
				border-radius: 50%;
				animation: waveExpand 3s ease-out infinite;

				&--1 {
					width: 100px;
					height: 100px;
					top: -50px;
					left: -50px;
					border-color: rgba(255, 107, 53, 0.4);
					animation-delay: 0s;
				}

				&--2 {
					width: 150px;
					height: 150px;
					top: -75px;
					left: -75px;
					border-color: rgba(255, 140, 66, 0.3);
					animation-delay: 1s;
				}

				&--3 {
					width: 200px;
					height: 200px;
					top: -100px;
					left: -100px;
					border-color: rgba(255, 182, 108, 0.2);
					animation-delay: 2s;
				}
			}
		}

		// 彩色光束效果
		&__light-beams {
			position: absolute;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);
			width: 280px;
			height: 280px;

			.light-beam {
				position: absolute;
				top: 50%;
				left: 50%;
				width: 2px;
				height: 80px;
				background: linear-gradient(to bottom,
						rgba(255, 107, 53, 0.8),
						rgba(255, 140, 66, 0.6),
						transparent);
				transform-origin: bottom center;
				animation: beamRotate 6s linear infinite;
				border-radius: 2px;
				box-shadow: 0 0 8px rgba(255, 107, 53, 0.5);

				&--1 {
					transform: translate(-50%, -100%) rotate(0deg);
					animation-delay: 0s;
				}

				&--2 {
					transform: translate(-50%, -100%) rotate(90deg);
					animation-delay: 1.5s;
					background: linear-gradient(to bottom,
							rgba(255, 140, 66, 0.8),
							rgba(255, 182, 108, 0.6),
							transparent);
				}

				&--3 {
					transform: translate(-50%, -100%) rotate(180deg);
					animation-delay: 3s;
					background: linear-gradient(to bottom,
							rgba(255, 182, 108, 0.8),
							rgba(255, 140, 66, 0.6),
							transparent);
				}

				&--4 {
					transform: translate(-50%, -100%) rotate(270deg);
					animation-delay: 4.5s;
					background: linear-gradient(to bottom,
							rgba(255, 107, 53, 0.8),
							rgba(255, 182, 108, 0.6),
							transparent);
				}
			}
		}
	}

	// 动画定义
	@keyframes fadeIn {
		from {
			opacity: 0;
		}

		to {
			opacity: 1;
		}
	}

	@keyframes glow {
		from {
			text-shadow: 0 2px 8px rgba(255, 255, 255, 0.5);
		}

		to {
			text-shadow: 0 2px 8px rgba(255, 255, 255, 0.5), 0 0 15px rgba(100, 100, 100, 0.3);
		}
	}

	// 立体脉冲动画
	@keyframes pulse3D {

		0%,
		100% {
			transform: scale(1) rotateX(0deg);
		}

		50% {
			transform: scale(1.02) rotateX(2deg);
		}
	}

	// 立体发光动画
	@keyframes countdownGlow3D {
		from {
			filter: drop-shadow(0 1px 0 #cc2e43) drop-shadow(0 2px 0 #b22738) drop-shadow(0 3px 0 #99202e) drop-shadow(0 4px 0 #801923) drop-shadow(0 5px 0 #661218) drop-shadow(0 8px 12px rgba(0, 0, 0, 0.3)) drop-shadow(0 0 20px rgba(255, 71, 87, 0.6));
		}

		to {
			filter: drop-shadow(0 2px 0 #cc2e43) drop-shadow(0 3px 0 #b22738) drop-shadow(0 4px 0 #99202e) drop-shadow(0 5px 0 #801923) drop-shadow(0 6px 0 #661218) drop-shadow(0 10px 16px rgba(0, 0, 0, 0.4)) drop-shadow(0 0 30px rgba(255, 71, 87, 0.8));
		}
	}

	@keyframes rotate {
		from {
			transform: translate(-50%, -50%) rotate(0deg);
		}

		to {
			transform: translate(-50%, -50%) rotate(360deg);
		}
	}

	@keyframes breathe {
		from {
			transform: translate(-50%, -50%) scale(1);
			opacity: 0.1;
		}

		to {
			transform: translate(-50%, -50%) scale(1.1);
			opacity: 0.2;
		}
	}

	// 百分比发光动画
	@keyframes percentageGlow {
		from {
			background: rgba(255, 71, 87, 0.1);
			border-color: rgba(255, 71, 87, 0.2);
			text-shadow: 0 1px 3px rgba(255, 71, 87, 0.3);
		}

		to {
			background: rgba(255, 71, 87, 0.15);
			border-color: rgba(255, 71, 87, 0.3);
			text-shadow: 0 1px 5px rgba(255, 71, 87, 0.5);
		}
	}

	// 色彩点缀动画
	@keyframes colorDotFloat {
		0% {
			opacity: 0;
			transform: translateY(0px) scale(0.5);
		}

		50% {
			opacity: 0.8;
			transform: translateY(-15px) scale(1);
		}

		100% {
			opacity: 0;
			transform: translateY(-30px) scale(0.5);
		}
	}

	@keyframes colorRingRotate {
		from {
			transform: translate(-50%, -50%) rotate(0deg);
		}

		to {
			transform: translate(-50%, -50%) rotate(360deg);
		}
	}

	@keyframes shimmer {
		0% {
			transform: translateX(-100%);
		}

		100% {
			transform: translateX(100%);
		}
	}

	@keyframes bounce {

		0%,
		20%,
		50%,
		80%,
		100% {
			transform: translateY(0);
		}

		40% {
			transform: translateY(-10px);
		}

		60% {
			transform: translateY(-5px);
		}
	}

	@keyframes sparkle {
		0% {
			opacity: 0;
			transform: scale(0) rotate(0deg);
		}

		50% {
			opacity: 0.6;
			transform: scale(1) rotate(180deg);
		}

		100% {
			opacity: 0;
			transform: scale(0) rotate(360deg);
		}
	}

	// 粒子浮动动画
	@keyframes particleFloat {
		0% {
			opacity: 0;
			transform: translateY(50px) scale(0);
		}

		10% {
			opacity: 1;
		}

		90% {
			opacity: 1;
		}

		100% {
			opacity: 0;
			transform: translateY(-50px) scale(1.5);
		}
	}

	// 几何图形旋转
	@keyframes geoRotate {
		from {
			transform: rotate(0deg);
		}

		to {
			transform: rotate(360deg);
		}
	}

	// 几何图形浮动
	@keyframes geoFloat {

		0%,
		100% {
			transform: translateY(0px) rotate(0deg);
		}

		50% {
			transform: translateY(-10px) rotate(180deg);
		}
	}

	// 几何图形自旋
	@keyframes geoSpin {
		0% {
			transform: rotate(0deg) scale(1);
		}

		50% {
			transform: rotate(180deg) scale(1.1);
		}

		100% {
			transform: rotate(360deg) scale(1);
		}
	}

	// 波浪扩展动画
	@keyframes waveExpand {
		0% {
			transform: scale(0);
			opacity: 0.8;
		}

		50% {
			opacity: 0.4;
		}

		100% {
			transform: scale(2);
			opacity: 0;
		}
	}

	// 光束旋转动画
	@keyframes beamRotate {
		0% {
			transform: translate(-50%, -100%) rotate(0deg);
			opacity: 1;
		}

		50% {
			opacity: 0.6;
		}

		100% {
			transform: translate(-50%, -100%) rotate(360deg);
			opacity: 1;
		}
	}

	// 响应式设计
	@media (max-width: 768px) {
		.seckill-countdown {
			&__modal {
				width: 85vw;
				height: 70vh;
				max-height: 500px;
				min-height: 400px;
				border-radius: 25px;
			}

			&__display {
				padding: 0 20px 20px;
			}

			&__title {
				font-size: 1.5rem;
			}

			&__seconds-digit {
				font-size: 7rem;
				letter-spacing: -4px;
			}

			&__seconds-bg {
				width: 140px;
				height: 140px;
			}

			&__seconds-glow {
				width: 170px;
				height: 170px;
			}

			&__color-dots {
				width: 200px;
				height: 200px;
			}

			&__color-ring {
				width: 180px;
				height: 180px;
			}

			&__seconds-label {
				font-size: 1.5rem;
			}

			&__progress-label {
				font-size: 0.8rem;
			}

			&__progress-percentage {
				font-size: 0.9rem;
				padding: 3px 6px;
			}
		}
	}

	@media (max-width: 480px) {
		.seckill-countdown {
			&__modal {
				width: 90vw;
				height: 65vh;
				max-height: 450px;
				min-height: 350px;
				border-radius: 20px;
			}

			&__display {
				padding: 0 15px 15px;
			}

			&__seconds {
				margin-bottom: 20px;
			}

			&__seconds-digit {
				font-size: 5.5rem;
				letter-spacing: -3px;
			}

			&__seconds-bg {
				width: 110px;
				height: 110px;
			}

			&__seconds-glow {
				width: 130px;
				height: 130px;
			}

			&__color-dots {
				width: 150px;
				height: 150px;
			}

			&__color-ring {
				width: 130px;
				height: 130px;
			}

			&__seconds-label {
				font-size: 1.2rem;
			}

			&__progress-label {
				font-size: 0.75rem;
			}

			&__progress-percentage {
				font-size: 0.85rem;
				padding: 2px 5px;
			}

			&__progress {
				height: 6px;
			}
		}
	}

	// 超小屏幕优化
	@media (max-width: 360px) {
		.seckill-countdown {
			&__modal {
				width: 95vw;
				height: 60vh;
				max-height: 400px;
				min-height: 320px;
				border-radius: 18px;
			}

			&__display {
				padding: 0 10px 10px;
			}

			&__seconds-digit {
				font-size: 4.5rem;
				letter-spacing: -2px;
			}

			&__seconds-bg {
				width: 90px;
				height: 90px;
			}

			&__seconds-glow {
				width: 110px;
				height: 110px;
			}

			&__color-dots {
				width: 120px;
				height: 120px;
			}

			&__color-ring {
				width: 100px;
				height: 100px;
			}

			&__seconds-label {
				font-size: 1rem;
			}
		}
	}
</style>